package com.ruoyi.tcm.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.tcm.domain.TcmKnowledgeBase;
import com.ruoyi.tcm.service.ITcmKnowledgeBaseService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 知识库Controller
 * 
 * @author cong
 * @date 2025-02-07
 */
@RestController
@RequestMapping("/tcm/knowledge_base")
public class TcmKnowledgeBaseController extends BaseController
{
    @Autowired
    private ITcmKnowledgeBaseService tcmKnowledgeBaseService;

    /**
     * 查询知识库列表
     */
    @PreAuthorize("@ss.hasPermi('tcm:knowledge_base:list')")
    @GetMapping("/list")
    public TableDataInfo list(TcmKnowledgeBase tcmKnowledgeBase)
    {
        startPage();
        List<TcmKnowledgeBase> list = tcmKnowledgeBaseService.selectTcmKnowledgeBaseList(tcmKnowledgeBase);
        return getDataTable(list);
    }

    /**
     * 导出知识库列表
     */
    @PreAuthorize("@ss.hasPermi('tcm:knowledge_base:export')")
    @Log(title = "知识库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TcmKnowledgeBase tcmKnowledgeBase)
    {
        List<TcmKnowledgeBase> list = tcmKnowledgeBaseService.selectTcmKnowledgeBaseList(tcmKnowledgeBase);
        ExcelUtil<TcmKnowledgeBase> util = new ExcelUtil<TcmKnowledgeBase>(TcmKnowledgeBase.class);
        util.exportExcel(response, list, "知识库数据");
    }

    /**
     * 获取知识库详细信息
     */
    @PreAuthorize("@ss.hasPermi('tcm:knowledge_base:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tcmKnowledgeBaseService.selectTcmKnowledgeBaseById(id));
    }

    /**
     * 新增知识库
     */
    @PreAuthorize("@ss.hasPermi('tcm:knowledge_base:add')")
    @Log(title = "知识库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TcmKnowledgeBase tcmKnowledgeBase)
    {
        return toAjax(tcmKnowledgeBaseService.insertTcmKnowledgeBase(tcmKnowledgeBase));
    }

    /**
     * 修改知识库
     */
    @PreAuthorize("@ss.hasPermi('tcm:knowledge_base:edit')")
    @Log(title = "知识库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TcmKnowledgeBase tcmKnowledgeBase)
    {
        return toAjax(tcmKnowledgeBaseService.updateTcmKnowledgeBase(tcmKnowledgeBase));
    }

    /**
     * 删除知识库
     */
    @PreAuthorize("@ss.hasPermi('tcm:knowledge_base:remove')")
    @Log(title = "知识库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tcmKnowledgeBaseService.deleteTcmKnowledgeBaseByIds(ids));
    }
}
